package XZK010404;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;

import XZK010404.dao.AirInfoDao;
import XZK010404.dao.AirInfoDaoImpl;
import XZK010404.dao.BaseDao;
import XZK010404.entity.AirInfo;

/**
 * JDBC 任务
 * 业务目标:
 * 根据需求完成各个功能
 * 技能目标:
 * 1. 使用 JDBC 操作 MySql 数据库
 * 2. MySql 数据库的使用
 * 3. Sql 的使用
 *
 * @author bing.zhang06@hand-china.com 2021/7/7 21:14
 **/
public class Main {
    private static BaseDao baseDao = new BaseDao();
    private static AirInfoDaoImpl airInfoDao = new AirInfoDaoImpl();
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) throws ParseException {
        try (Scanner in = new Scanner(System.in)) {
            System.out.println("===欢迎使用航班信息管理系统===");
            airInfoDao.setBaseDao(baseDao);
            while (true) {
                System.out.println("请选择操作：（1）列出所有航班（2）按起飞时间查询（3）按目的地查询" +
                        "（4）删除航班（5）更新航班（6）离开系统");
                String text = in.nextLine();
                int no = Integer.parseInt(text);
                switch (no) {
                    case 1:
                        List<AirInfo> infoList = airInfoDao.listAll();
                        for (AirInfo info : infoList) {
                            System.out.println(info);
                        }
                        break;
                    case 2:
                        String departureDate = in.nextLine();
                        List<AirInfo> byDepartureDate = airInfoDao.getByDepartureDate(departureDate);
                        for (AirInfo info : byDepartureDate) {
                            System.out.println(info);
                        }
                        break;
                    case 3:
                        String destination = in.nextLine();
                        List<AirInfo> byDestination = airInfoDao.getByDestination(destination);
                        for (AirInfo info : byDestination) {
                            System.out.println(info);
                        }
                        break;
                    case 4:
                        String airNo = in.nextLine();
                        int rows = airInfoDao.deleteByAirNo(airNo);
                        if (rows > 0) {
                            System.out.println("删除成功!");
                        } else {
                            System.out.println("删除失败!");
                        }
                        break;
                    case 5:
                        break;
                    case 6:
                        System.out.println("===再见===");

                        System.exit(0);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
